﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace ECCSystem.DataAccess
{
	class ClsTeamGoal : DBObject 
    {
		public DataSet GetTeamGoal(DateTime dtTime)
		{
			SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@Goal_Month", SqlDbType.DateTime)};
			parameters[0].Value = dtTime;

			return RunProcedure("sp_TeamGoal_GetListByTime", parameters, "TeamGoal");
		}

		public DataSet GetTeamGoal()
		{
			return RunProcedure("sp_TeamGoal_GetList", new IDataParameter[] { }, "TeamGoal");
		}

		public void AddTeamGoal(string strEfficiency, string strFactAchievement, 
				string strDefect, string strDefectQuotietyrash, DateTime dtGoal_Month)
        {
			SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@TeamGoal_Efficiency", SqlDbType.NVarChar,100),
															 new SqlParameter("@TeamGoal_FactAchievement", SqlDbType.NVarChar,100),
															 new SqlParameter("@TeamGoal_Defect", SqlDbType.NVarChar,100),
															 new SqlParameter("@TeamGoal_DefectQuotietyrash", SqlDbType.NVarChar,100),
															 new SqlParameter("@Goal_Month", SqlDbType.DateTime)};

			parameters[0].Value = strEfficiency;
			parameters[1].Value = strFactAchievement;
			parameters[2].Value = strDefect;
			parameters[3].Value = strDefectQuotietyrash;
			parameters[4].Value = dtGoal_Month;
			this.RunProcedure("sp_TeamGoal_Add", parameters, "TeamGoal");
        }

		public void DeleteTeamGoal(string strID)
		{
			SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.UniqueIdentifier) };
			
			Guid guid = new Guid(strID);
			parameters[0].Value = guid;
			this.RunProcedure("sp_TeamGoal_Delete", parameters, "TeamGoal");
		}

		public void UpdateTeamGoal(string strEfficiency, string strFactAchievement, 
				string strDefect, string strDefectQuotietyrash, DateTime dtGoal_Month,string strID)
		{
			SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@TeamGoal_Efficiency", SqlDbType.NVarChar,100),
															 new SqlParameter("@TeamGoal_FactAchievement", SqlDbType.NVarChar,100),
															 new SqlParameter("@TeamGoal_Defect", SqlDbType.NVarChar,100),
															 new SqlParameter("@TeamGoal_DefectQuotietyrash", SqlDbType.NVarChar,100),
															 new SqlParameter("@Goal_Month", SqlDbType.DateTime),
															 new SqlParameter("@ID", SqlDbType.UniqueIdentifier)};
			Guid guid = new Guid(strID);
			parameters[0].Value = strEfficiency;
			parameters[1].Value = strFactAchievement;
			parameters[2].Value = strDefect;
			parameters[3].Value = strDefectQuotietyrash;
			parameters[4].Value = dtGoal_Month;
			parameters[5].Value = guid;
			this.RunProcedure("sp_TeamGoal_Update", parameters, "TeamGoal");
		}
    }
}
